﻿using System;
using System.Collections.Generic;
using System.Linq;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle.Interactions;
using LBoL.Core.Cards;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;

namespace ProbeMod.Cards
{
    public sealed class ProbeXelnagaArtifactDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            var config = GetCardDefaultConfig();

            config.Rarity = Rarity.Common;
            config.Type = CardType.Attack;
            config.TargetType = TargetType.SingleEnemy;
            config.Colors = new List<ManaColor>() { ManaColor.White };

            config.Cost = new ManaGroup() { White = 1 ,Any = 1};
            config.UpgradedCost = new ManaGroup() { Any = 2 };

            config.RelativeEffects = new List<string>() { "ProbeXelnagaArtifactKeywordSe" };
            config.UpgradedRelativeEffects = new List<string>() { "ProbeXelnagaArtifactKeywordSe" };

            config.Damage = 12;
            config.UpgradedDamage = 15;

            config.Mana = new ManaGroup() { Philosophy = 2 };
            config.UpgradedMana = new ManaGroup() { Philosophy = 2 };

            config.Value1 = 2;

            config.Index = CardIndexGenerator.GetUniqueIndex(config);
            return config;
        }
    }

    /// <summary>
    /// 萨尔那加神器
    /// 打12,升级所有手牌
    /// 如果3神器，升级所有牌，并且+2彩色抽2
    /// </summary>
    [EntityLogic(typeof(ProbeXelnagaArtifactDef))]
    public sealed class ProbeXelnagaArtifact : ProbeCard
    {
        
        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            yield return AttackAction(selector);

            if (
                Battle.Player.StatusEffects.Any(e => e.Config.RelativeEffects.Any(s => s == "ProbeXelnagaArtifactKeywordSe"))
                && GameRun.Player.Exhibits.Any(c => c.Config.RelativeEffects.Any(s => s == "ProbeXelnagaArtifactKeywordSe"))
                )
            {
                //  升级所有卡
                List<Card> list = (from c in base.Battle.EnumerateAllCards()
                                   where c.CanUpgradeAndPositive && c != this
                                   select c).ToList();
                if (list.Count > 0)
                {
                    yield return new UpgradeCardsAction(list);
                }

                yield return new GainManaAction(Mana);
                yield return new DrawManyCardAction(Value1);
            }
            else
            {
                yield return UpgradeAllHandsAction();
            }


        }
    }
}
